#---
# Excerpted from "Rails for PHP Developers",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material, 
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose. 
# Visit http://www.pragmaticprogrammer.com/titles/ndphpr for more book information.
#---
class MeetingsController < ApplicationController
  before_filter :find_meeting, :except => [:index, :new, :create]

  def index
    @upcoming_meetings = Meeting.upcoming_meetings
    @past_meetings     = Meeting.past_meetings
  end

  def show
  end

  def new
    @meeting = Meeting.new
  end

  def edit
  end

  def create
    @meeting = Meeting.new(params[:meeting])

    if @meeting.save
      flash[:notice] = 'Meeting successfully created.'
      redirect_to :action => "index"
    else
      render :action => "new"
    end
  end

  def update
    if @meeting.update_attributes(params[:meeting])
      flash[:notice] = 'Meeting successfully updated.'
      redirect_to :action => "show", :id => params[:id]
    else
      render :action => "edit"
    end
  end

  def destroy
    @meeting.destroy
    flash[:notice] = 'Meeting successfully destroyed.'
    redirect_to :action => "index"
  end

  private

  def find_meeting
    @meeting = Meeting.find(params[:id])
  end
end
